package com.game.animation;

import android.graphics.Canvas;
import android.graphics.Color;

import com.game.utils.AnimationInterpolatorUtil;

/**
 * 百叶窗
 * @author Administrator
 *
 */
public class AnimationGradualchangeSquare extends AnimationGradualchange {
	int row=1;//行数
	int col=1;//列数
	float span_w=0;//宽
	float span_h=0;//高
	
	
	public AnimationGradualchangeSquare(AnimationObject object,AnimationGradualchangeCallBack callBack,int row,int col,float time){
		super(object,callBack,time);
		this.row=row;
		this.col=col;
		if(row==0||col==0){
			//正方形   以一边为基准
			if(row==0){
				span_w=object.getWidth()/col;	
				span_h=span_w;
				this.row=(int) (object.getHeight()/span_h)+1;
			}else{
				span_h=object.getHeight()/row;
				span_w=span_h;
				this.col=(int) (object.getWidth()/span_w)+1;
			}
		}else{
			//矩形
			span_w=object.getWidth()/col+1;
			span_h=object.getHeight()/row+1;
		}
	}
	
	@Override
	public void step(Canvas canvas,float perc) {
		float x = object.getPostX();
		float y = object.getPostY();
		
		for(int i=0;i<row;i++){
			//外层画列 遍历行
			for(int j=0;j<col;j++){
				//内层画一行 遍历列
				float currentW = perc*span_w;//当前矩形的宽
				float currentH = perc*span_h;//当前矩形的高
				float sx=j*span_w+(span_w-currentW)/2;
				sx=sx+x;//加上基础值
				float sy=i*span_h+(span_h-currentH)/2;
				sy=sy+y;
				float ex=sx+currentW;
				float ey=sy+currentH;
				canvas.drawRect(sx,sy,ex,ey,paint);
			}
		}
	}

	public int getSpeedType() {
		return speedType;
	}

	public void setSpeedType(int speedType) {
		this.speedType = speedType;
	}
	
}

